package com.crl.map.model
{
	import com.crl.map.unit.def.AbstractDef;
	import com.crl.map.unit.ele.BgEle;
	
	import flash.geom.Point;
	import flash.utils.Dictionary;

	public class MapModel
	{
		/**
		 * 模型标识; 
		 */		
		public var guid:String;
		
		/**
		 * 库 
		 */		
		public var library:Dictionary;
		
		/**
		 * 定义列表; 
		 */		
		private var defs:Array;
		
		/**
		 * 背景参数定义; 
		 */		
		public var bgRow:int;
		public var bgCol:int
		public var bgW:int;
		public var bgH:int;
		
		/**
		 * 背景列表; 
		 */		
		protected var bgEles:Vector.<BgEle>;
		
		
		/**
		 * 区块参数定义; 
		 */		
		public var tw:int;
		public var th:int;
		public var row:uint;
		public var col:uint;
		
		/**
		 * 原点坐标; 
		 */		
		public var ox:int;
		public var oy:int;
		
		public function MapModel()
		{
		}
		
		public function initializeBackground():void{
			bgEles=new Vector.<BgEle>();
			
			var x:String,y:String;
			var bgEle:BgEle;
			var bgDef:AbstractDef;
			for(var i:int=0;i<bgRow;i++){
				for(var j:int=0;j<bgCol;j++){
					
					x="000"+j;
					y="000"+i;
					
					bgDef=new AbstractDef();
					bgDef.x=j*bgW;
					bgDef.y=i*bgH;
					bgDef.id=x.substring(x.length-3)+y.substring(y.length-3);
					
					bgEle=new BgEle(bgDef);
					bgEle.path=guid+"/"+bgDef.id+".jpg";
					
					bgEles[i*bgCol+j]=bgEle;
				}
			}
		}
		
		/**
		 * 取得入口点; 
		 * @return 
		 * 
		 */
		public function getEntreace():Point{
			return new Point(3*_tw,3*_th)
		}
		
		/**
		 * 取得背景定义; 
		 * @return 
		 * 
		 */		
		public function getBgEles():Vector.<BgEle>{
			return bgEles;
		}
		
		public function get row():uint{
			return _row;
		}
		public function get col():uint{
			return _col;
		}
	}
}